<!--上传组件-->
<template>
  <el-upload
    class="upload-demo"
    action=""
    name="file"
    :limit='1'
    :http-request="handleUpload"
    :on-remove="handleRemove"
    :file-list="file_list"
    list-type="picture-card"
    >
    <el-button size="small" type="primary">点击上传</el-button>
    <div slot="tip" class="el-upload__tip">{{upload_tip}}</div>
  </el-upload>
</template>

<script>
  import { uploadImage } from '@/api/upload.js';
  export default{
     name:'Upload',
     props:['catch_urls','remove_urls','limit','file_list','upload_tip'],
     methods:{
        handleRemove(file){
          let remove_index=file.name;   //注意：这边每次都用下标来赋值给name
          //index表示下标，移除哪一张图片
          this.remove_urls(remove_index);
        },
        handleUpload(file){
          let that=this;
          let fd=new FormData();
          fd.append('file[]',file.file);
          uploadImage(fd).then(function(response){
              if(response.data.code==1){
                  that.catch_urls(response.data.urls);
              }else{
                  that.$message({
                      message:'图片上传失败',
                      type:'error',
                  });
              }
          })
        }
     }
  }
</script>

<style>
</style>
